<?php

namespace app\service;

use app\models\Incr;

class StatService
{

    /**
     * 获取首页统计数据
     * @return array
     */
    public function getHomeStat()
    {
        $keysHash = Incr::getAllKey();
        $incrNameArray = array(
            Incr::INCR_PUBLICITY_VIDEO_PLAY_STAT,
            Incr::INCR_PUBLICITY_BROWSE_STAT,
            Incr::INCR_JUMP_LINK1_STAT,
            Incr::INCR_JUMP_LINK2_STAT,
            Incr::INCR_MEMBER_APPLY_STAT
        );

        $resultHash = array();

        foreach ($incrNameArray as $incrName) {
            $name = $incrName[1];

            if (isset($keysHash[$incrName[0]])) {
                $stat = $keysHash[$incrName[0]]['incr'];
            } else {
                $stat = 0;
            }

            $resultHash[] = array(
                'name' => $name,
                'stat' => $stat
            );
        }

        $resultHash[] = array(
            'name' => '点赞数',
            'stat' => \Yii::$app->get('redis')->get('like')
        );

        return $resultHash;
    }

}